clc
clear
load('inputdata_v1.mat')

%{
***********************************************************************************
Triangular distribution parameters for input data of baseline model
Input data (Building #1 = ("input.one.mat"), Building #2 = ("input.two.mat"))
***********************************************************************************
%}

for a = [1 2]
    if a==1
        c = 'one';
    else c = 'two';
    end
b = input.(c);
triangle = @(table, row) makedist('Triangular','a',b{row,5},'b',b{row,4},'c',b{row,6});
shower.freq.pd = triangle(b, 1);
shower.dur.pd = triangle(b, 2);
shower.flow.pd = triangle(b, 3);
bathtub.freq.pd = triangle(b, 4);
bathtub.vol.pd = triangle(b, 5);
toilet.freq.pd = triangle(b, 6);
toilet.vol.pd = triangle(b, 7);
faucet.bath.freq.pd =  triangle(b, 8);
faucet.bath.fract.pd =  triangle(b, 9);
faucet.bath.dur.pd =  triangle(b, 10);
faucet.bath.flow.pd =  triangle(b, 11);
faucet.bath.thro.pd =  triangle(b, 12);
faucet.kit.cook.pd =  triangle(b, 13);
faucet.kit.freq.pd =  triangle(b, 14);
faucet.kit.vol.pd =  triangle(b, 15);
cap.pd =  triangle(b, 16);
faucet.kit.other.pd =  triangle(b, 17);
faucet.kit.clotheswashinghand.pd =  triangle(b, 18);
dishwasher.freq.pd = triangle(b, 19);
dishwasher.vol.pd = triangle(b, 20);
clotheswasher.freq.pd = triangle(b, 21);
clotheswasher.vol.pd = triangle(b, 22);
leak.vol.pd = triangle(b, 23);

%{
***********************************************************************************
Cumulative distribution functions of baseline model generated by Monte Carlo simulation (modeled data in Fig. 5)
***********************************************************************************
%}

ss = 10000;
rng('default');

cap.s = random(cap.pd,ss,1);

leak.vol.s = random(leak.vol.pd,ss,1);
modeled.(c).leak = leak.vol.s;

m = ('shower');
n = {'freq', 'dur', 'flow'};
   for i = 1:length(n) 
   shower.(n{i}).s = random(shower.(n{i}).pd,ss,1);
   end
modeled.(c).(m) = shower.flow.s.* shower.freq.s.* shower.dur.s; 
   
m = ('bathtub');
n = {'freq', 'vol'};
   for i = 1:length(n) 
   bathtub.(n{i}).s = random(bathtub.(n{i}).pd,ss,1);
   end
modeled.(c).(m) = bathtub.freq.s.* bathtub.vol.s;   
   
m = ('toilet');
n = {'freq', 'vol'};
   for i = 1:length(n) 
   toilet.(n{i}).s = random(toilet.(n{i}).pd,ss,1);
   end   
modeled.(c).(m).flush = toilet.freq.s.* toilet.vol.s;
modeled.(c).(m).leak = leak.vol.s;
modeled.(c).(m).flushleak = modeled.(c).(m).flush + modeled.(c).(m).leak;

m = ('faucet');
o = ('bath');
n = {'freq', 'dur', 'flow', 'fract', 'thro'};
   for i = 1:length(n) 
   faucet.(o).(n{i}).s = random(faucet.(o).(n{i}).pd,ss,1);
   end  
modeled.(c).(m).(o) = faucet.bath.freq.s.* faucet.bath.fract.s.* faucet.bath.dur.s.* faucet.bath.flow.s.* faucet.bath.thro.s;

o = ('kit');
n = {'freq', 'vol', 'cook', 'other', 'clotheswashinghand'};
   for i = 1:length(n) 
   faucet.(o).(n{i}).s = random(faucet.kit.(n{i}).pd,ss,1);
   end
modeled.(c).(m).(o).dsh = (faucet.kit.cook.s.* faucet.kit.freq.s.* faucet.kit.vol.s)./cap.s;
modeled.(c).(m).(o).other = faucet.kit.other.s;
modeled.(c).(m).(o).clotheswashinghand = faucet.kit.clotheswashinghand.s;
modeled.(c).(m).(o).dshother = modeled.(c).(m).(o).dsh + modeled.(c).(m).(o).other;
modeled.(c).(m).(o).total = modeled.(c).(m).(o).dshother + modeled.(c).(m).(o).clotheswashinghand;

m = ('dishwasher');
n = {'freq', 'vol'};
   for i = 1:length(n) 
   dishwasher.(n{i}).s = random(dishwasher.(n{i}).pd,ss,1);
   end    
modeled.(c).(m) = dishwasher.freq.s.* dishwasher.vol.s;

m = ('clotheswasher');
n = {'freq', 'vol'};
   for i = 1:length(n) 
   clotheswasher.(n{i}).s = random(clotheswasher.(n{i}).pd,ss,1);
   end
   
modeled.(c).(m) = clotheswasher.freq.s.* clotheswasher.vol.s;
modeled.(c).total = modeled.(c).shower + modeled.(c).bathtub + modeled.(c).toilet.flushleak + modeled.(c).faucet.bath + modeled.(c).faucet.kit.total + modeled.(c).dishwasher + modeled.(c).clotheswasher;

modeled.(c).(c).awayforschool = modeled.(c).toilet.flush + modeled.(c).faucet.bath;
modeled.(c).(c).personalhygiene = modeled.(c).shower + modeled.(c).bathtub;
modeled.(c).(c).dishwashing = modeled.(c).faucet.kit.dsh + modeled.(c).dishwasher;
modeled.(c).(c).leak = modeled.(c).leak;

%{
***********************************************************************************
Results: Median, minimum and maximum of modeled end use water consumption data for baseline model (Table 5)
%}

format shortg
sd =3;
sg = 'significant';
func = @median;
modeled.(c).table5_med = table (func(round(modeled.(c).shower,sd, sg)), func(round(modeled.(c).bathtub,sd,sg)), func(round(modeled.(c).toilet.flush,sd,sg)), func(round(modeled.(c).toilet.flushleak,sd,sg)), func(round(modeled.(c).faucet.bath,sd,sg)), func(round(modeled.(c).faucet.kit.dshother,sd,sg)),func(round(modeled.(c).faucet.kit.total,sd,sg)), func(round(modeled.(c).dishwasher,sd,sg)), func(round(modeled.(c).clotheswasher,sd,sg)), func(round(modeled.(c).total,sd,sg)));
e = {'Shower' 'Bathtub' 'Toilet' 'ToiletLeak' 'BathroomFaucet' 'KitchenFaucet' 'KitchenFaucetClotheswashingbyHand' 'Dishwasher' 'ClothesWasher' 'Total'};
modeled.(c).table5_med.Properties.VariableNames = e;

func = @min;
modeled.(c).table5_min = table (func(round(modeled.(c).shower,sd,sg)), func(round(modeled.(c).bathtub,sd,sg)), func(round(modeled.(c).toilet.flush,sd,sg)), func(round(modeled.(c).toilet.flushleak,sd,sg)), func(round(modeled.(c).faucet.bath,sd,sg)), func(round(modeled.(c).faucet.kit.dshother,sd,sg)),func(round(modeled.(c).faucet.kit.total,sd,sg)), func(round(modeled.(c).dishwasher,sd,sg)), func(round(modeled.(c).clotheswasher,sd,sg)), func(round(modeled.(c).total,sd,sg)));
modeled.(c).table5_min.Properties.VariableNames = e;

func = @max;
modeled.(c).table5_max = table (func(round(modeled.(c).shower,sd,sg)), func(round(modeled.(c).bathtub,sd,sg)), func(round(modeled.(c).toilet.flush,sd,sg)), func(round(modeled.(c).toilet.flushleak,sd,sg)), func(round(modeled.(c).faucet.bath,sd,sg)), func(round(modeled.(c).faucet.kit.dshother,sd,sg)),func(round(modeled.(c).faucet.kit.total,sd,sg)), func(round(modeled.(c).dishwasher,sd,sg)), func(round(modeled.(c).clotheswasher,sd,sg)), func(round(modeled.(c).total,sd,sg)));
modeled.(c).table5_max.Properties.VariableNames = e;

%{
***********************************************************************************
Performance metrics for baseline model (PBIAS, NSE) (Table 5)
Input data (Building #1 = ("metered.one.mat"), Building #2 = ("metered.two.mat'))
***********************************************************************************
%}

metered.(c).shower(isnan(metered.(c).shower))=[];
metered.(c).bathtub(isnan(metered.(c).bathtub))=[];
metered.(c).toilet(isnan(metered.(c).toilet))=[];
metered.(c).faucet.bath(isnan(metered.(c).faucet.bath))=[];
metered.(c).faucet.kit(isnan(metered.(c).faucet.kit))=[];
    if a == 1;
        c = 'one';
       metered.(c).dishwasher(isnan(metered.(c).dishwasher))=[];
       metered.(c).clotheswasher(isnan(metered.(c).clotheswasher))=[];
    end
metered.(c).total(isnan(metered.(c).total))=[];

func = @mean;
metered.(c).table5 = table (round(func(metered.(c).shower),sd,sg), round(func(metered.(c).bathtub),sd,sg), round(func(metered.(c).toilet),sd,sg), round(func(metered.(c).toilet),sd,sg), round(func(metered.(c).faucet.bath),sd,sg), round(func(metered.(c).faucet.kit),sd,sg), round(func(metered.(c).faucet.kit),sd,sg), round(func(metered.(c).dishwasher),sd,sg), round(func(metered.(c).clotheswasher),sd,sg), round(func(metered.(c).total),sd,sg));
metered.(c).table5.Properties.VariableNames = e;

sd = 2;
distribution.(c).shower = shower;
distribution.(c).bathtub = bathtub;
distribution.(c).toilet = toilet;
distribution.(c).faucet.bath = faucet.bath;
distribution.(c).faucet.kit = faucet.kit;
distribution.(c).cap = cap;
distribution.(c).dishwasher = dishwasher;
distribution.(c).clotheswasher = clotheswasher;
distribution.(c).leak = leak;

m = {'shower', 'bathtub', 'dishwasher', 'clotheswasher', 'total'};
    for i = 1:length(m)
actual = sort(metered.(c).(m{i}));
mod = sort(modeled.(c).(m{i}));
actual_rank = (tiedrank(actual) / length(actual))*100;
mod_rank = prctile(mod,actual_rank);
obs = actual;
mod = mod_rank;
PBIAS.(c).(m{i}) = {round((sum(obs - mod).*100)/sum(obs),sd,sg)};
NSE.(c).(m{i}) = {round(1 - (sum((obs - mod).^2)/(sum((obs - mean(obs)).^2))),sd,sg)}; 
    end
 
m = ('toilet');
n = {'flush', 'flushleak'};
   for i = 1:length(n) 
actual = sort(metered.(c).(m));
mod = sort(modeled.(c).(m).(n{i}));       
actual_rank = (tiedrank(actual) / length(actual))*100;
mod_rank = prctile(mod,actual_rank);
obs = actual;
mod = mod_rank;
PBIAS.(c).(m).(n{i}) = {round((sum(obs - mod).*100)/sum(obs),sd,sg)};
NSE.(c).(m).(n{i}) = {round(1 - (sum((obs - mod).^2)/(sum((obs - mean(obs)).^2))),sd,sg)}; 
   end

m = ('faucet');
o = ('bath'); 
actual = sort(metered.(c).(m).(o));
mod = sort(modeled.(c).(m).(o));       
actual_rank = (tiedrank(actual) / length(actual))*100;
mod_rank = prctile(mod,actual_rank);
obs = actual;
mod = mod_rank;
PBIAS.(c).(m).(o) = {round((sum(obs - mod).*100)/sum(obs),sd,sg)};
NSE.(c).(m).(o) = {round(1 - (sum((obs - mod).^2)/(sum((obs - mean(obs)).^2))),sd,sg)}; 

o = ('kit');
n = {'dshother', 'total'};
    for i = 1:length(n) 
actual = sort(metered.(c).(m).(o));
mod = sort(modeled.(c).(m).(o).(n{i}));       
actual_rank = (tiedrank(actual) / length(actual))*100;
mod_rank = prctile(mod,actual_rank);
obs = actual;
mod = mod_rank;
PBIAS.(c).(m).(o).(n{i}) = {round((sum(obs - mod).*100)/sum(obs),sd,sg)};
NSE.(c).(m).(o).(n{i}) = {round(1 - (sum((obs - mod).^2)/(sum((obs - mean(obs)).^2))),sd,sg)};        
    end
    
%{
***********************************************************************************
Results: Performance metrics for baseline model (PBIAS) (Table 5)
%}
PBIAS.(c).table5 = table (PBIAS.(c).shower, PBIAS.(c).bathtub, PBIAS.(c).toilet.flush, PBIAS.(c).toilet.flushleak, PBIAS.(c).faucet.bath, PBIAS.(c).faucet.kit.dshother, PBIAS.(c).faucet.kit.total, PBIAS.(c).dishwasher, PBIAS.(c).clotheswasher, PBIAS.(c).total);
PBIAS.(c).table5.Properties.VariableNames = e;

%{
***********************************************************************************
Results: Performance metrics for baseline model (NSE) (Table 5)
%}
NSE.(c).table5 = table (NSE.(c).shower, NSE.(c).bathtub, NSE.(c).toilet.flush, NSE.(c).toilet.flushleak, NSE.(c).faucet.bath, NSE.(c).faucet.kit.dshother, NSE.(c).faucet.kit.total, NSE.(c).dishwasher, NSE.(c).clotheswasher, NSE.(c).total);
NSE.(c).table5.Properties.VariableNames = e;
    
%{
***********************************************************************************
Results: Median of modeled end use water consumption data for Fig. 5 (baseline model)
***********************************************************************************
%}

modeled.(c).fig5.(c).(c) = table (modeled.(c).(c).awayforschool, modeled.(c).(c).personalhygiene, modeled.(c).(c).dishwashing, modeled.(c).(c).leak);
modeled.(c).fig5.(c).(c).Properties.VariableNames = {'AwayforSchool' 'PersonalHygiene' 'DishWashing' 'Leak'};
end

%{
***********************************************************************************
Cumulative distribution functions of alternative model (switch of Building #1 with Building #2 tenants, and Building #2 with Building #1 tenants) generated by Monte Carlo simulation for Fig. 6
***********************************************************************************
%}

for a = [1 2]
    if a==1
        c = 'one';
    else c = 'two';
    end

    if c== 'one';
        d = 'two';
    else d = 'one';
    end
modeled.(c).(d).awayforschool = (distribution.(d).toilet.freq.s.* distribution.(c).toilet.vol.s) + (distribution.(d).faucet.bath.freq.s.* distribution.(c).faucet.bath.fract.s.* distribution.(d).faucet.bath.dur.s.* distribution.(c).faucet.bath.flow.s.* distribution.(c).faucet.bath.thro.s);
modeled.(c).(d).personalhygiene = (distribution.(c).shower.flow.s.* distribution.(d).shower.freq.s.* distribution.(d).shower.dur.s) + (distribution.(d).bathtub.freq.s.* distribution.(d).bathtub.vol.s);
modeled.(c).(d).dishwashing = (distribution.(c).dishwasher.freq.s.* distribution.(c).dishwasher.vol.s) + ((distribution.(d).faucet.kit.cook.s.* distribution.(c).faucet.kit.freq.s.* distribution.(c).faucet.kit.vol.s)./ distribution.(d).cap.s);
modeled.(c).(d).leak = distribution.(c).leak.vol.s;

%{
***********************************************************************************
Results: Median of modeled end use water consumption data for Fig. 6 (alternative model, switch of Building #1 with Building #2 tenants, and Building #2 with Building #1 tenants)
%}

modeled.(c).fig5.(c).(d) = table (modeled.(c).(d).awayforschool, modeled.(c).(d).personalhygiene, modeled.(c).(d).dishwashing, modeled.(c).(d).leak);
modeled.(c).fig5.(c).(d).Properties.VariableNames = {'AwayforSchool' 'PersonalHygiene' 'DishWashing' 'Leak'};
end

%{
***********************************************************************************
Triangular distribution parameters for input data of alternative model (water conservation measures) for Fig. 7
Input data (Building #1 and Building #2 ("input.three.mat"))
***********************************************************************************
%}

e = 'three';
b = input.(e);
triangle = @(table, row) makedist('Triangular','a',b{row,5},'b',b{row,4},'c',b{row,6});
shower.flow.xlow.pd = triangle(b, 1);
shower.flow.low.pd = triangle(b, 2);
toilet.vol.dual.pd = triangle(b, 3);
faucet.bath.flow.pd =  triangle(b, 4);
bathtub.freq.pd = triangle(b, 5);
leak.vol.pd = triangle(b, 6);
dishwasher.vol.pd =  triangle(b, 7);

%{
***********************************************************************************
Cumulative distribution functions of alternative model (water conservation measures) generated by Monte Carlo simulation for Fig. 7
***********************************************************************************
%}

distribution.(e).shower.flow.xlow.s = random(shower.flow.xlow.pd,ss,1);
distribution.(e).shower.flow.low.s = random(shower.flow.low.pd,ss,1);
distribution.(e).toilet.vol.dual.s = random(toilet.vol.dual.pd,ss,1);
distribution.(e).faucet.bath.flow.s =   random(faucet.bath.flow.pd,ss,1);
distribution.(e).bathtub.freq.s = random(bathtub.freq.pd,ss,1);
distribution.(e).leak.vol.s = random(leak.vol.pd,ss,1);
distribution.(e).dishwasher.vol.s = random(dishwasher.vol.pd,ss,1);

for a = [1 2]
    if a==1
        c = 'one';
    else c = 'two';
    end

    if c== 'one'
        d = 'two';
    else d = 'one';
    end
modeled.(c).(e).shower.xlow = (distribution.(e).shower.flow.xlow.s.* distribution.(c).shower.freq.s.* distribution.(c).shower.dur.s);
modeled.(c).(e).shower.low = (distribution.(e).shower.flow.low.s.* distribution.(c).shower.freq.s.* distribution.(c).shower.dur.s);
modeled.(c).(e).toilet.vol.dual = (distribution.(c).toilet.freq.s.* distribution.(e).toilet.vol.dual.s);
modeled.(c).(e).faucet.bath = (distribution.(c).faucet.bath.freq.s.* distribution.(c).faucet.bath.fract.s.* distribution.(c).faucet.bath.dur.s.* distribution.(e).faucet.bath.flow.s.* distribution.(c).faucet.bath.thro.s);
modeled.(c).(e).bathtub = (distribution.(e).bathtub.freq.s.* distribution.(c).bathtub.vol.s);
modeled.(c).(e).leak.vol = (distribution.(e).leak.vol.s);
modeled.(c).(e).dishwasher = (distribution.(c).dishwasher.freq.s.* distribution.(e).dishwasher.vol.s);
modeled.one.three.dishwasherinstallation = modeled.one.dishwasher - modeled.one.three.dishwasher;
modeled.two.three.dishwasherinstallation = modeled.two.faucet.kit.dsh - (modeled.one.three.dishwasher + ((distribution.two.faucet.kit.cook.s.* distribution.one.faucet.kit.freq.s.* distribution.one.faucet.kit.vol.s)./ distribution.two.cap.s));

%{
Water consumption savings (water consumption savings = baseline model consumption - water savings model consumption)
%}

modeled.(c).fig6.shower.xlow = modeled.(c).shower - modeled.(c).(e).shower.xlow;
modeled.(c).fig6.shower.low = modeled.(c).shower - modeled.(c).(e).shower.low;
modeled.(c).fig6.toilet.dual = modeled.(c).toilet.flush - modeled.(c).(e).toilet.vol.dual;
modeled.(c).fig6.faucet.bath = modeled.(c).faucet.bath -  modeled.(c).(e).faucet.bath;
modeled.(c).fig6.bathtub = modeled.(c).bathtub - modeled.(c).(e).bathtub;
modeled.(c).fig6.leak = modeled.(c).leak - modeled.(c).(e).leak.vol;
modeled.(c).fig6.dishwasher = modeled.(c).dishwasher - modeled.(c).(e).dishwasher;

%{
***********************************************************************************
Results: Median of modeled end use water consumption savings data for Fig. 7 (alternative model, water savings measures)
%}

modeled.(c).fig6 = table (modeled.(c).fig6.shower.xlow, modeled.(c).fig6.toilet.dual, modeled.(c).fig6.shower.low, modeled.(c).fig6.faucet.bath, modeled.(c).fig6.bathtub, modeled.(c).fig6.leak, modeled.(c).(e).dishwasherinstallation);
modeled.(c).fig6.Properties.VariableNames = {'ShowerheadBar1' 'DualFlushToiletBar2' 'ShowerheadBar3' 'BathroomFaucetBar4' 'DecreaseBathingBar5' 'LeakMitigationBar6' 'DishwashingInstallationBar7'};
end

%{
***********************************************************************************
Results summary
***********************************************************************************
Table 5
%}
 
Table5 = vertcat(metered.one.table5,metered.two.table5, modeled.one.table5_med, modeled.one.table5_min, modeled.one.table5_max, modeled.two.table5_med, modeled.two.table5_min, modeled.two.table5_max, PBIAS.one.table5, PBIAS.two.table5, NSE.one.table5, NSE.two.table5);
Table5 = table2array(Table5);
Table5 = array2table(Table5.');
e = {'Shower' 'Bathtub' 'Toilet' 'Toilet + Leaks' 'Bathroom Sink Faucet' 'Kitchen Sink Faucet' 'Kitchen Sink Faucet + Clothes Washing by Hand' 'Dishwasher' 'Clothes Washer' 'Total'};
Table5.Properties.RowNames = e;
Table5.Properties.VariableNames = {'B1_metered_mean' 'B2_metered_mean' 'B1_modeled_median' 'B1_modeled_min' 'B1_modeled_max' 'B2_modeled_median' 'B2_modeled_min' 'B2_modeled_max' 'B1_pbias' 'B2_pbias' 'B1_nse' 'B2_nse'};
Table5
 
%{
***********************************************************************************
Figure 6
%}

c = 'one';
d = 'two';
e = {'Away for work/school','Personal hygiene','Dish washing', 'Leaks'};

sd = 3;
%Median of modeled end use water consumption data for Fig. 6 (baseline model, Building #1 (B1_w_B1))
B1 = [
round(median(modeled.(c).fig5.(c).(c).AwayforSchool),sd,sg);
round(median(modeled.(c).fig5.(c).(c).PersonalHygiene),sd,sg);
round(median(modeled.(c).fig5.(c).(c).DishWashing),sd,sg);
round(median(modeled.(c).fig5.(c).(c).Leak),sd,sg);
];

%Median of modeled end use water consumption data for Fig. 6 (alternative model, Building #1 with Building #2 tenants (B1_w_B2))
B1_w_B2 = [
round(median(modeled.(c).fig5.(c).(d).AwayforSchool),sd,sg);
round(median(modeled.(c).fig5.(c).(d).PersonalHygiene),sd,sg);
round(median(modeled.(c).fig5.(c).(d).DishWashing),sd,sg);
round(median(modeled.(c).fig5.(c).(d).Leak),sd,sg);
];

%Median of modeled end use water consumption data for Fig. 6 (baseline model, Building #2 (B2_w_B2))
B2_w_B1 = [
round(median(modeled.(d).fig5.(d).(c).AwayforSchool),sd,sg);
round(median(modeled.(d).fig5.(d).(c).PersonalHygiene),sd,sg);
round(median(modeled.(d).fig5.(d).(c).DishWashing),sd,sg);
round(median(modeled.(d).fig5.(d).(c).Leak),sd,sg);
];

%Median of modeled end use water consumption data for Fig. 6 (alternative model, Building #2 with Building #1 tenants (B2_w_B1))
B2 = [
round(median(modeled.(d).fig5.(d).(d).AwayforSchool),sd,sg);
round(median(modeled.(d).fig5.(d).(d).PersonalHygiene),sd,sg);
round(median(modeled.(d).fig5.(d).(d).DishWashing),sd,sg);
round(median(modeled.(d).fig5.(d).(d).Leak),sd,sg);
];

Fig6 = table(B1, B1_w_B2, B2_w_B1, B2, 'RowNames',e)

%{
***********************************************************************************
Figure 7
%}

c = 'one';
d = 'two';
e = {'Showerhead retrofitting (1.9 L/min)','Dual flush toilet (1.9 - 3.4 L/flush)','Showerhead retrofitting (5.7 L/min)', 'Bathroom sink faucet retrofitting (1.9 L/min)','Decrease bathing frequency to 0.09 bath/(cap*d)','Leak mitigation (e.g., flapper replacement)','Dishwashing installation (EnergyStar, 13 L/load)'};

sd = 3;
%Median of modeled end use water savings data for Fig. 6 (alternative model, water conservation measures, Building #1 (B1))
B1 = [
round(median(modeled.(c).fig6.ShowerheadBar1),sd,sg);
round(median(modeled.(c).fig6.DualFlushToiletBar2),sd,sg);
round(median(modeled.(c).fig6.ShowerheadBar3),sd,sg);
round(median(modeled.(c).fig6.BathroomFaucetBar4),sd,sg);
round(median(modeled.(c).fig6.DecreaseBathingBar5),sd,sg);
round(median(modeled.(c).fig6.LeakMitigationBar6),sd,sg);
round(median(modeled.(c).fig6.DishwashingInstallationBar7),sd,sg);
];

%Median of modeled end use water savings data for Fig. 7 (alternative model, water conservation measures, Building #2 (B2))
B2 = [
round(median(modeled.(d).fig6.ShowerheadBar1),sd,sg);
round(median(modeled.(d).fig6.DualFlushToiletBar2),sd,sg);
round(median(modeled.(d).fig6.ShowerheadBar3),sd,sg);
round(median(modeled.(d).fig6.BathroomFaucetBar4),sd,sg);
round(median(modeled.(d).fig6.DecreaseBathingBar5),sd,sg);
round(median(modeled.(d).fig6.LeakMitigationBar6),sd,sg);
round(median(modeled.(d).fig6.DishwashingInstallationBar7),sd,sg);
];

Fig7 = table(B1, B2, 'RowNames',e)

%{
***********************************************************************************
Delete unused workspace variables
***********************************************************************************
%}

clear a b c d e i m n o ss sd sg
clear shower bathtub toilet faucet cap dishwasher clotheswasher leak
clear actual actual_rank mod mod_rank obs func triangle
clear B1 B2 B1_w_B1 B1_w_B2 B2_w_B2 B2_w_B1 PBIAS NSE